﻿using UnityEngine;
using System.Collections;

namespace Room
{
    public class PlayerAIStateArress : PlayerAIStateBase
    {
        GameObject obj;
        float delayTime = 3f;
        float currTime = 0f;
        protected override void OnEnter()
        {
            //如果不是自己
            if(long.Parse(controller.owner.name) != StaticData.playerData.playerId)
            {
                controller.owner.charactorManager.DestroyCharactor(controller.owner.name);
                if(obj!=null)
                {
                    GameObjectPoolManager.Instance.Unspawn(obj);
                }
                obj = GameObjectPoolManager.Instance.Spawn(RoomField.particleDieAb, CommonMethod.GetAssetNameFromAssetBundleName(RoomField.particleDieAb));
                obj.transform.SetParent(controller.owner.transform);
                obj.transform.localScale = Vector3.one;
                obj.transform.localPosition = Vector3.zero;
                obj.SetActive(true);
            }

            delayTime = Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.FieldPVPKeep;
            currTime = 0f;
            
        }

        protected override void OnTick()
        {
            currTime += Time.deltaTime;
            if(currTime >= delayTime )
            {
                if(long.Parse(controller.owner.name) == StaticData.playerData.playerId)
                {
                    ManagerController.Instance.TrySceneTransfer(ServerScene.Town, Vector3.zero, null, () =>
                    {
                        UI.PageManager.Instance.OpenPage("TownPage", "forceJump=1");
                    });
                }
                else
                {
                    if (obj != null)
                    {
                        GameObjectPoolManager.Instance.Unspawn(obj);
                    }
                }
                currTime = 0f;
            }
        }


        protected override void OnLeave()
        {
        }
    }
}